@@ -1,280 +0,0 @@
<template>
  <el-dialog v-model="visible" title="查看课程列表" width="95%" append-to-body style="height: 800px">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div class="search" v-show="showSearch">
        <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
          <el-form-item label="名称" prop="testName">
            <el-input v-model="queryParams.testName" placeholder="请输入名称" clearable :disabled="isDisable" style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="学段" prop="testPeriod">
            <!-- <el-input v-model="queryParams.testPeriod" placeholder="请输入学段" clearable style="width: 240px" @keyup.enter="handleQuery" /> -->
            <el-select v-model="queryParams.testPeriod" placeholder="请选择学段" clearable>
              <el-option v-for="dict in sys_period" :key="dict.value" :label="dict.label" :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="年级" prop="testGrade">
            <el-select v-model="queryParams.testGrade" placeholder="请选择学段" clearable>
              <el-option v-for="dict in sys_grade" :key="dict.value" :label="dict.label" :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="班级" prop="testClass">
            <el-input v-model="queryParams.testClass" placeholder="请输入班级" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="学科" prop="testSubject">
            <!-- <el-input v-model="queryParams.testSubject" placeholder="请输入学科" clearable style="width: 240px" @keyup.enter="handleQuery" /> -->
            <el-select v-model="queryParams.testSubject" clearable placeholder="请选择学科" :disabled="isDisable">
            <el-option v-for="dict in subjectOptions" :key="dict.id" :label="dict.subjectName" :value="dict.id"></el-option>
          </el-select>
          </el-form-item>
          <el-form-item label="授课老师" prop="testTeacher">
            <!-- <el-input v-model="queryParams.testTeacher" placeholder="请输入授课老师" clearable style="width: 240px" @keyup.enter="handleQuery" /> -->
            <el-select v-model="queryParams.testTeacher"  clearable  placeholder="请选择教师" >
  <el-option v-for="dict in teacherOptions" :key="dict.id" :label="dict.name" :value="dict.id"></el-option>
</el-select>
          </el-form-item>
          <el-form-item label="授课教室" prop="testRoot">
            <el-input v-model="queryParams.testRoot" placeholder="请输入授课教室" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="授课时间" prop="testDate">
            <el-date-picker clearable v-model="queryParams.testDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择授课时间" :disabled="isDisable" />
            <span style="margin:0 5px;"> -</span>
          <el-date-picker clearable v-model="queryParams.testDateEnd" type="date" value-format="YYYY-MM-DD" placeholder="年/月/日" :disabled="isDisable" />
        
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            <el-button type="primary" @click="handleAdd" v-hasPermi="['core:testTeachSchedule:add']">新增</el-button>
          </el-form-item>
        </el-form>
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <h2>实验排课列表</h2>
      </template>
      <el-table v-loading="loading" :data="testTeachScheduleList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="课程编号" align="center" prop="id" v-if="true" />
        <el-table-column label="名称" align="center" prop="testName" />
        <el-table-column label="学段" align="center" prop="testPeriod">
          <template #default="scope">
            <dict-tag :options="sys_period" :value="scope.row.testPeriod" />
          </template>
        </el-table-column>
        <el-table-column label="年级" align="center" prop="testGrade" >
            <template #default="scope">
            <dict-tag :options="sys_grade" :value="scope.row.testGrade" />
          </template>
        </el-table-column>
        <el-table-column label="班级" align="center" prop="testClass" />
        <el-table-column label="学科" align="center" prop="testSubject" >
            <template #default="scope">
                 {{ getSubjectNameById(subjectOptions, scope.row.testSubject) }}
            </template>
        </el-table-column>
        <el-table-column label="授课老师" align="center" prop="testTeacher" >
            <template #default="scope">
                 {{ getTeacherNameById(teacherOptions, scope.row.testTeacher) }}
            </template>
        </el-table-column>
        <el-table-column label="授课教室" align="center" prop="testRoot" />
        <el-table-column label="授课时间" align="center" prop="testDate" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.testDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
          <template #default="scope">
            <el-button type="text" size="small" @click="handleUpdate(scope.row)" v-hasPermi="['core:testTeachSchedule:edit']">编辑</el-button>
            <el-button type="text" size="small" @click="handleView(scope.row)">查看</el-button>
            <el-button type="text" size="small" @click="handleDelete(scope.row)" v-hasPermi="['core:testTeachSchedule:remove']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>
  </el-dialog>
</template>

<script setup name="TestTeachSchedule" lang="ts">
import {
  listTestTeachSchedule,
  getTestTeachSchedule,
  delTestTeachSchedule,
  addTestTeachSchedule,
  updateTestTeachSchedule
} from '@/api/core/testTeachSchedule';
import { TestTeachScheduleVO, TestTeachScheduleQuery, TestTeachScheduleForm } from '@/api/core/testTeachSchedule/types';
const router = useRouter();
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { sys_notice_type, sys_period,sys_grade } = toRefs<any>(proxy?.useDict('sys_notice_type', 'sys_period','sys_grade'));
const testTeachScheduleList = ref<TestTeachScheduleVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const visible = ref(false);
const queryFormRef = ref<ElFormInstance>();
const testTeachScheduleFormRef = ref<ElFormInstance>();
const isDisable =ref(true)
// 共有数据方法  学科 ,教师
import { getSubjectNameById,getTeacherNameById } from '@/utils/index';
import { useSubjectList ,useTeacherList} from '@/composables/useSubjectList';
const { subjectOptions, fetchSubjectList } = useSubjectList();
const { teacherOptions, fetchTeacherList } = useTeacherList();
const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

const initFormData: TestTeachScheduleForm = {
  testName: undefined,
  testPeriod: undefined,
  testGrade: undefined,
  testClass: undefined,
  testSubject: undefined,
  testTeacher: undefined,
  testRoot: undefined,
  testDate: undefined
};
const data = reactive<PageData<TestTeachScheduleForm, TestTeachScheduleQuery>>({
  form: { ...initFormData },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    testName: undefined,
    testPeriod: undefined,
    testGrade: undefined,
    testClass: undefined,
    testSubject: undefined,
    testTeacher: undefined,
    testRoot: undefined,
    testDate: undefined,
    testDateEnd: undefined,
    params: {}
  },
  rules: {
    testName: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
    testPeriod: [{ required: true, message: '学段不能为空', trigger: 'blur' }],
    testGrade: [{ required: true, message: '年级不能为空', trigger: 'blur' }],
    testClass: [{ required: true, message: '班级不能为空', trigger: 'blur' }],
    testSubject: [{ required: true, message: '学科不能为空', trigger: 'blur' }],
    testTeacher: [{ required: true, message: '授课老师不能为空', trigger: 'blur' }],
    testRoot: [{ required: true, message: '授课教室不能为空', trigger: 'blur' }],
    testDate: [{ required: true, message: '授课时间不能为空', trigger: 'blur' }]
  }
});

const { queryParams, form, rules } = toRefs(data);
const openDialog = (param: string) => {
  queryParams.value.testName = param.id;
  queryParams.value.testSubject = param.subject?+param.subject:undefined;
  // queryParams.value.testDate = param.testDate?param.testDate:undefined;
  // queryParams.value.testDateEnd = param.testDateEnd?param.testDateEnd:undefined;
  console.log('参数===',param,queryParams.value);
  getList();
  fetchSubjectList()
  fetchTeacherList()
  visible.value = true;
};

/** 查询教学实验排课列表 */
const getList = async () => {
  // testTeachScheduleList.value = [
  //   { testName: 111, testPeriod: 2, testGrade: 2, testClass: 1111, testSubject: '1853736542128500739', testTeacher: 1, testRoot: 1111, testDate: 1111 }
  // ];
  loading.value = true;
  const res = await listTestTeachSchedule(queryParams.value);
   testTeachScheduleList.value = res.rows;
  total.value = res.total;
  loading.value = false;
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};

/** 多选框选中数据 */
const handleSelectionChange = (selection: TestTeachScheduleVO[]) => {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
};

/** 新增按钮操作 */
const handleAdd = () => {
  router.push({ path: '/course/testTeachSchedule/panel/', query: { type: 0 } });
};
/*** 查看按钮 */
const handleView = async (row?: TestTeachScheduleVO) => {
  const id = row?.id || ids.value[0];
  router.push({ path: '/course/testTeachSchedule/panel/', query: { id: id, type: 2 } });
};
/** 修改按钮操作 */
const handleUpdate = async (row?: TestTeachScheduleVO) => {
  const id = row?.id || ids.value[0];
  router.push({ path: '/course/testTeachSchedule/panel/', query: { id: id, type: 1 } });
};


/** 删除按钮操作 */
const handleDelete = async (row?: TestTeachScheduleVO) => {
  const _ids = row?.id || ids.value;
  await proxy?.$modal.confirm('是否确认删除教学实验排课编号为"' + _ids + '"的数据项？').finally(() => (loading.value = false));
  await delTestTeachSchedule(_ids);
  proxy?.$modal.msgSuccess('删除成功');
  await getList();
};

/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download(
    'core/testTeachSchedule/export',
    {
      ...queryParams.value
    },
    `testTeachSchedule_${new Date().getTime()}.xlsx`
  );
};
defineExpose({
  openDialog
});
</script>
